//Page Object
import regeneratorRuntimer from '../../lib/runtime/runtime'
import { request } from '../../request/index.js'
import { showToast, showModel } from "../../utils/asyncWx.js"
const config = require("../../utils/config.js")
Page({
    data: {
        swiperList: [
            { url: '../../icons/Administrator_page/swiper_one.jpg' },
            { url: '../../icons/Administrator_page/swiper_one.jpg' },
            { url: '../../icons/Administrator_page/swiper_one.jpg' }
        ],
        showDialog: false,
        // 船只照片
        ships: [],
        // 船员照片
        crew: [],

        // 轮播图
        Img: [],
        // 二维码图片
        code: []


    },
    // 二维码图片
    code: [],
    Pic: [],
    shipAbout: {
        id: 1
    },
    order: true,
    sortFieldNme: 'id',
    //船舶id
    id: '',
    // 用于信息提示
    toggleDialog() {
        console.log(11111)
        this.setData({
            showDialog: !this.data.showDialog
        })
    },
    // 初始化页面加载
    onLoad(e) {
        console.log('-----------------')
        console.log(e)
        console.log(this.id)
        this.id = e.id
        this.getImg()
        this.getData()
    },
    // 获取页面数据
    async getData() {
        this.shipAbout.id = this.id
        const res = await request({ url: "/ship/getShipAllById.controller", data: { shipaboutvo: this.shipAbout } })
        console.log(res)
        res.data.ShipAboutVO.shipCode = config.BaseUrl + 'permanent/' + res.data.ShipAboutVO.shipCode
        this.code.push(res.data.ShipAboutVO.shipCode)

        this.setData({
            ShipAboutVO: res.data.ShipAboutVO,
            ShipDetailedPO: res.data.ShipDetailedPO,
            shipImagePOS: res.data.shipImagePOS,
            shipCurdPOS: res.data.shipCurdPOS
        })
        const arrOne = []
        const arrTwo = []

        for (var i = 0; i < res.data.shipImgPOS.length; i++) {

            if (res.data.shipImgPOS[i].shipImgType === '1') {
                arrOne.push(config.BaseUrl + res.data.shipImgPOS[i].shipImg)
            } else if (res.data.shipImgPOS[i].shipImgType === '0') {
                arrTwo.push(config.BaseUrl + res.data.shipImgPOS[i].shipImg)
            }
        }

        this.setData({
            ships: arrOne,
            crew: arrTwo
        })
        console.log(this.data.ships)
    },

    // 获取轮播图的图片
    async getImg() {
        const res = await request({ url: "/picture/getBannerList.controller", method: "POST", data: { sortFieldNme: this.sortFieldNme, order: this.order } })
        console.log(res.data.resultList)
        console.log(res.data.resultList[1].picture)
        for (var i = 0; i < res.data.resultList.length; i++) {
            console.log(111)
            this.Pic.push(config.BaseUrl + 'permanent/picture/' + res.data.resultList[i].picture)
        }
        console.log(this.Pic)
        this.setData({
            Img: this.Pic
        })
    },
    // 退出按钮
    async logout() {
        wx.showModal({
            title: '提示', //提示的标题,
            content: '是否退出登录', //提示的内容,
            showCancel: true, //是否显示取消按钮,
            success: res => {
                if (res.confirm) {
                    // 调用退出登录
                    this.logouts()

                } else if (res.cancel) {
                    console.log(res.cancel)
                }
            }
        });

    },
    //退出
    async logouts() {
        const res = await request({ url: '/logout.controller' })
        if (res.msg == '登出成功') {
            wx.removeStorageSync({ key: 'openid' });
            wx.redirectTo({ url: '/pages/Start_page/index' });
        }
    },
    // 点击放大图片
    previewImage: function(e) {
        console.log(e)
        var current = e.target.dataset.src;
        wx.previewImage({
            current: current, // 当前显示图片的http链接  
            urls: this.data.ships // 需要预览的图片http链接列表  
        })
    },

    //
    previewImageOne(e) {
        var current = e.target.dataset.src;
        wx.previewImage({
            current: current, // 当前显示图片的http链接  
            urls: this.data.crew // 需要预览的图片http链接列表  
        })
    },

    previewImageTwo(e) {
        var current = e.target.dataset.src;
        wx.previewImage({
            current: current,
            urls: this.code
        });
    }
});